require("../css/login.less")
document.ready(function () {
    let homePage = document.querySelector("#homePage")
    let phoneInp = document.querySelector("#phoneInp")
    let passwordInp = document.querySelector("#passwordInp")
    homePage.addEventListener("click", function () {
        let phone = phoneInp.value
        let password = passwordInp.value
        let hint=document.querySelector("#hint")
        if (!window.$utils.isPhone(phone)) {
            hint.textContent = "您输入的账号有误"
        } else if (!window.$utils.isPassword(password)) {
            hint.textContent = "请输入正确的密码格式"
        } else {
            hint.textContent =""
            axios.post("http://139.9.177.51:8099/users/login", {
                "account": phone,
                "password": password
            })
                .then(function (res) {
                    let ret = res.data
                    if (ret.status == 0) {
                        // alert("登录成功")
                        window.$utils.toast("success", "登录成功")
                        window.localStorage.setItem("user", JSON.stringify(ret.data.user))
                        setTimeout(function () {
                            location.href = "./home.html"
                        }, 3000)
                    } else {
                        window.$utils.toast("fail", "账户或密码错误")
                    }
                })
                .catch(function (error) {
                    console.log(error);
                })
        }

    })
})